package org.kzwl.book.controller.web;


import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.kzwl.comm.advice.Consts;
import org.kzwl.comm.pojo.ResponseData;
import org.kzwl.comm.pojo.bo.CuHeritageBO;
import org.kzwl.comm.pojo.bo.QueryAdminCuHeritageBO;
import org.kzwl.comm.pojo.bo.heritage.HeritageBasicBO;
import org.kzwl.comm.pojo.bo.heritage.QueryDetailsBO;
import org.kzwl.comm.pojo.dto.heritage.HeritageBasicDTO;
import org.kzwl.comm.pojo.dto.heritage.QueryDetailsDTO;
import org.kzwl.comm.utils.MyUtils;
import org.kzwl.entity.web.CuHeritage;
import org.kzwl.service.web.CuHeritageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 非遗文化保护 前端控制器
 * </p>
 *
 * @author 张国伟/郭家恒
 * @since 2020-12-21
 */
@Api("web非遗文化保护")
@RestController
@RequestMapping("/cu-heritage")
public class CuHeritageController {

    @Autowired
    CuHeritageService cuHeritageService;

    @ApiOperation(value = "PC添加非遗保护信息")
    @PostMapping("/saveOne")
    public ResponseData<Void> saveOne(@RequestBody @Valid CuHeritageBO cuHeritageBO)
    {
        return cuHeritageService.saveOne(cuHeritageBO);
    }


    @ApiOperation(value = "PC查询非遗保护信息")
    @PostMapping("/queryPage")
    public ResponseData<IPage<CuHeritage>> queryPage(@RequestBody QueryAdminCuHeritageBO queryAdminCuHeritageBO)
    {
        return cuHeritageService.queryPage(queryAdminCuHeritageBO);
    }

    @ApiOperation(value = "PC查询一条非遗保护信息")
    @PostMapping("/queryOne")
    public ResponseData<CuHeritage> queryOne(@RequestBody Long Id)
    {
        return cuHeritageService.queryOne(Id);
    }

    @ApiOperation(value = "PC修改一条非遗保护信息")
    @PostMapping("/updateOne")
    public ResponseData<Void> updateOne(@RequestBody CuHeritageBO cuHeritageBO)
    {
        return cuHeritageService.updateOne(cuHeritageBO);
    }
    @ApiOperation(value = "PC删除一条非遗保护信息")
    @PostMapping("/deleteId")
    public ResponseData<Void> deleteId(@RequestBody Long Id)
    {
        return cuHeritageService.deleteId(Id);
    }

    @ApiOperation(value = "非遗文化保护基础查询")
    @PostMapping("/queryBasic")
    public ResponseData<IPage<HeritageBasicDTO>> queryBasic(@RequestBody HeritageBasicBO bo)
    {
        IPage<HeritageBasicDTO> page = cuHeritageService.queryBasic(bo);
        return new ResponseData<>(page);
    }

    @ApiOperation(value = "非遗文化保护详细")
    @PostMapping("/queryDetails")
    public ResponseData<QueryDetailsDTO> queryDetails(@RequestBody QueryDetailsBO bo)
    {
        QueryDetailsDTO dto = cuHeritageService.queryDetails(bo);
        return new ResponseData<>(dto);
    }

    @ApiOperation(value = "非遗文化保护推荐")
    @PostMapping("/queryRecommend")
    public ResponseData<List<HeritageBasicDTO>> queryRecommend()
    {
        List<HeritageBasicDTO> list = cuHeritageService.queryRecommend();
        list.forEach(l->{
            l.setCuHeritageContent("");
            String s = MyUtils.regExHtml(l.getCuHeritageContent());
            l.setCuHeritageContent(s);
        });
        return new ResponseData<>(list);
    }
}
